﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:rep="urn:report-extended-utilities"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl rep">
  <xsl:output method="xml" indent="yes"/>
  <xsl:param name="report-name">SharePoint Generic Report</xsl:param>
  <xsl:param name="report-chart-type">Pie</xsl:param>
  <xsl:param name="report-legend-title">Lists Usage</xsl:param>
  <xsl:param name="report-date" />
  <xsl:key name="BaseTemplate" match="//WebApplications/WebApplication/Sites/Site/Webs/Web/Lists/List" use="@BaseTemplate" />
  <xsl:key name="BaseType" match="//WebApplications/WebApplication/Sites/Site/Webs/Web/Lists/List" use="@BaseType" />
  <xsl:template match="/">
    <xsl:variable name="report-legend-title">Lists size</xsl:variable>
    <Report Name="{$report-name}" ChartType="{$report-chart-type}" LegendTitle="{$report-legend-title}">
      <Filters>
        <Filter Name="Lists Item Count" FilterAttribute="Type" FilterValue="ItemCount" />
        <Filter Name="Lists Base Templates" FilterAttribute="Type" FilterValue="BaseTemplate" />
        <Filter Name="Lists Base Types" FilterAttribute="Type" FilterValue="BaseType" />
      </Filters>
      <Series>
        <Serie Name="Lists Item Count">
          <Item Type="ItemCount" Name="Tiny : 0 - 20" Date="{$report-date}">
            <xsl:attribute name="Value">
              <xsl:value-of select="count(//WebApplications/WebApplication/Sites/Site/Webs/Web/Lists/List[@ItemCount &lt;= 20])"/>
            </xsl:attribute>
          </Item>
          <Item Type="ItemCount" Name="Standard : 21 - 100" Date="{$report-date}">
            <xsl:attribute name="Value">
              <xsl:value-of select="count(//WebApplications/WebApplication/Sites/Site/Webs/Web/Lists/List[@ItemCount &gt; 20 and @ItemCount &lt;= 100])"/>
            </xsl:attribute>
          </Item>
          <Item Type="ItemCount" Name="High : 101 - 2000" Date="{$report-date}">
            <xsl:attribute name="Value">
              <xsl:value-of select="count(//WebApplications/WebApplication/Sites/Site/Webs/Web/Lists/List[@ItemCount &gt; 100 and @ItemCount &lt;= 2000])"/>
            </xsl:attribute>
          </Item>
          <Item Type="ItemCount" Name="Very High : +2000" Date="{$report-date}">
            <xsl:attribute name="Value">
              <xsl:value-of select="count(//WebApplications/WebApplication/Sites/Site/Webs/Web/Lists/List[@ItemCount &gt; 2000])"/>
            </xsl:attribute>
          </Item>
        </Serie>
        <Serie name="Lists Base Templates">
          <xsl:for-each select="//WebApplications/WebApplication/Sites/Site/Webs/Web/Lists/List[generate-id(.)=generate-id(key('BaseTemplate',@BaseTemplate))]">
            <xsl:variable name="ListBaseTemplate" select="@BaseTemplate" />
            <xsl:variable name="ListTemplateCount" select="count(//WebApplications/WebApplication/Sites/Site/Webs/Web/Lists/List[@BaseTemplate = $ListBaseTemplate])" />
            <xsl:if test="contains('0123456789', substring($ListBaseTemplate, 1, 1)) = false and $ListTemplateCount &gt; 2 and substring($ListBaseTemplate, string-length($ListBaseTemplate) - 6, 7) != 'Catalog'">
              <Item Type="BaseTemplate" Name="{$ListBaseTemplate}" Value="{$ListTemplateCount}" Date="{$report-date}" />
            </xsl:if>
          </xsl:for-each>
        </Serie>
        <Serie name="Lists Base Types">
          <xsl:for-each select="//WebApplications/WebApplication/Sites/Site/Webs/Web/Lists/List[generate-id(.)=generate-id(key('BaseType',@BaseType))]">
            <xsl:variable name="ListBaseType" select="@BaseType" />
            <Item Type="BaseType" Name="{$ListBaseType}" Date="{$report-date}">
              <xsl:attribute name="Value">
                <xsl:value-of select="count(//WebApplications/WebApplication/Sites/Site/Webs/Web/Lists/List[@BaseType= $ListBaseType])"/>
              </xsl:attribute>
            </Item>
          </xsl:for-each>
        </Serie>
      </Series>
    </Report>
  </xsl:template>
</xsl:stylesheet>
